package com.atguigu.bigdata.spark.core.rdd.operator.transform;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;
import org.apache.spark.api.java.function.VoidFunction;
import org.stringtemplate.v4.ST;

/* 从服务器日志数据apache.log中获取用户请求URL资源路径 */
public class Spark01_RDD_Operator_Transform_JAVA_2 {
    public static void main(String[] args) {
        // TODO 准备环境
        SparkConf conf = new SparkConf().setMaster("local[*]").setAppName("sparkCore");
        JavaSparkContext sc = new JavaSparkContext(conf);

        JavaRDD<String> rdd = sc.textFile("datas/apache.log");

        JavaRDD<String> mapRdd = rdd.map(new Function<String, String>() {
            @Override
            public String call(String s) throws Exception {
                return (s.split(" "))[6];
            }
        });

        mapRdd.foreach(new VoidFunction<String>() {
            @Override
            public void call(String s) throws Exception {
                System.out.println(s);
            }
        });

        sc.stop();
    }
}
